package com.kmproject.haifu.mvp.ui.adapter;

import android.content.Intent;
import android.support.annotation.Nullable;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.jess.arms.http.imageloader.ImageLoader;
import com.kmproject.haifu.R;
import com.kmproject.haifu.mvp.model.entity.beans.ObtainedSecondHandBean;
import com.kmproject.haifu.mvp.model.entity.beans.SecondHandInfoBean;
import com.kmproject.haifu.mvp.ui.activity.SecondHandInfoShowActivity;

import java.util.List;

public class SenondHandObtainedAdapter extends BaseQuickAdapter<ObtainedSecondHandBean, BaseViewHolder> {
  private ItemClickcallBack mitemClickcallBack;
    public SenondHandObtainedAdapter(@Nullable List<ObtainedSecondHandBean> data,ItemClickcallBack itemClickcallBack) {
        super(R.layout.mystore_selectstory_item, data);
        mitemClickcallBack=itemClickcallBack;
    }

    @Override
    protected void convert(BaseViewHolder helper, ObtainedSecondHandBean item) {
        helper.<RecyclerView>getView(R.id.mystore_selectstory_item_RecyclerView).setLayoutManager(new LinearLayoutManager(mContext));
        helper.<TextView>getView(R.id.mystore_selectstory_item_title_txt).setText(item.getTime()+"年发布");
        SenondHandObtainedItemAdapter adapter=new SenondHandObtainedItemAdapter(item.getResult());
        adapter.openLoadAnimation(BaseQuickAdapter.SCALEIN);
        adapter.openLoadAnimation(BaseQuickAdapter.SCALEIN);
        helper.<RecyclerView>getView(R.id.mystore_selectstory_item_RecyclerView).setAdapter(adapter);
        adapter.setOnItemClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(BaseQuickAdapter madapter, View view, int position) {
             //去详情
                Intent intent=new Intent(mContext, SecondHandInfoShowActivity.class);
                intent.putExtra("secondHandId",adapter.getItem(position).getSecondHandId());
                intent.putExtra("type","userCenter");
                mContext.startActivity(intent);
            }
        });

    adapter.setOnItemChildClickListener(new OnItemChildClickListener() {
        @Override
        public void onItemChildClick(BaseQuickAdapter madapter, View view, int position) {
            //删除
            mitemClickcallBack.callBack(adapter.getItem(position));
        }
    });
    }

    public  interface ItemClickcallBack{
        void callBack(SecondHandInfoBean secondHandInfoBean);
    }
}
